/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.dusin.util;

import java.util.regex.Pattern;

/**
 *
 * @author dusin
 */
public class FormatUtil {
    //是否符合的日期类型 yyyy-MM-dd或者 yyyy/MM/dd
    public static boolean isValidDate(String date){
        boolean flag = false;
        String pattern ="(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)"
                +"|(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})/(((0[13578]|1[02])/(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)/(0[1-9]|[12][0-9]|30))|(02/(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))/02/29)";//yyyy-MM-dd,可以判断闰年二月份
        flag =Pattern.matches(pattern, date);
        return flag;
    }
    //验证时间  hh:mm:ss
    public static boolean isValidTime(String time){
        String pattern="(([0-1]\\d)|(2[0-4])):[0-5]\\d:[0-5]\\d";
        return Pattern.matches(pattern, time);
    }
    
    public static boolean isValidDateTime(String dataTime){
        if(dataTime==null||dataTime.length()<18){
            return false;
        }
        String date = dataTime.substring(0,10);
        String time = dataTime.substring(10).trim();
        return isValidDate(date)&&isValidTime(time);
    }
    //判断是否合法车牌号码，含农用车牌，不是很精确
    public static boolean isValidPlateNo(String plateNo){
          String pattern = "([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}(([A-HJ-Z]{1}[A-HJ-NP-Z0-9]{5})|([0-9]{2}[A-Z0-9]{5})|([A-HJ-Z]{1}(([DF]{1}[A-HJ-NP-Z0-9]{1}[0-9]{4})|([0-9]{5}[DF]{1})))|([A-HJ-Z]{1}[A-D0-9]{1}[0-9]{3}警)))|([0-9]{6}使)|((([沪粤川云桂鄂陕蒙藏黑辽渝]{1}A)|鲁B|闽D|蒙E|蒙H)[0-9]{4}领)|(WJ[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼·•]{1}[0-9]{4}[TDSHBXJ0-9]{1})|([VKHBSLJNGCE]{1}[A-DJ-PR-TVY]{1}[0-9]{5})";
        return Pattern.matches(pattern, plateNo);
    }
    
    //判断是否是浮点数的字符串
    public static boolean isValidNumber(String number){
        String pattern ="^[0-9]+.?[0-9]*$";
        return Pattern.matches(pattern, number);
    }
}
